package logic

import (
	"context"
	"zhihu/mobels/cache"
	"zhihu/mobels/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowProblemLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowProblemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowProblemLogic {
	return &ShowProblemLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowProblemLogic) ShowProblem(in *zhihurpc.ShowProblemRequest) (*zhihurpc.ShowProblemResponse, error) {
	// todo: add your logic here and delete this line
	var problem mysql.Problem
	mysql.DB.Where("id?", in.ProblemId).Find(&problem)

	cache.Rdb.Incr(l.ctx, "top"+problem.Title)

	return &zhihurpc.ShowProblemResponse{
		Title:   problem.Title,
		Content: problem.Content,
		UserId:  problem.UserId,
	}, nil
}
